package ModelLayer;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class DvdTest.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class DvdTest
{
    /**
     * Default constructor for test class DvdTest
     */
    public DvdTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    @Test
    public void addCopy()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        ModelLayer.Copy copy1 = new ModelLayer.Copy("1", "2013", "2000");
        dvd1.addCopy(copy1);
        assertEquals(1,dvd1.amountOfCopies());
    }

    @Test
    public void deleteCopy()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        ModelLayer.Copy copy1 = new ModelLayer.Copy("1", "2013", "2000");
        dvd1.addCopy(copy1);
        dvd1.deleteCopy(copy1);
        assertEquals(0, dvd1.amountOfCopies());
    }
    
    /*
     * Test if find copy can find a copy in the array
     */
    @Test
    public void findCopy()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        ModelLayer.Copy copy1 = new ModelLayer.Copy("1", "2013", "2000");
        dvd1.addCopy(copy1);
        ModelLayer.Copy copy2 = new ModelLayer.Copy("2", "2010", "100");
        dvd1.addCopy(copy2);
        assertEquals(copy2, dvd1.findCopy("2"));
    }
    
    /*
     * Test that findCopy returns null if search String isnt in arrayList. 
     */
    @Test
    public void findCopyNotThere()
    {
        ModelLayer.Dvd dvd1 = new ModelLayer.Dvd("DBDB", "Harry Potter 4", "Elton John", "1999");
        ModelLayer.Copy copy1 = new ModelLayer.Copy("1", "2013", "2000");
        dvd1.addCopy(copy1);
        ModelLayer.Copy copy2 = new ModelLayer.Copy("2", "2010", "100");
        dvd1.addCopy(copy2);
        assertEquals(null, dvd1.findCopy("dd"));        
    }
}
